// Reader.java - 读者实体类
package com.library.entity;

import java.time.LocalDate;

public class Reader {
    private String readerId;
    private String name;
    private String gender;
    private String phone;
    private String email;
    private String department;
    private ReaderType type;
    private LocalDate registerDate;
    private LocalDate expiryDate;
    private ReaderStatus status;
    private int maxBorrowCount;
    private int maxBorrowDays;

    public enum ReaderType {
        STUDENT, TEACHER, STAFF, EXTERNAL
    }

    public enum ReaderStatus {
        ACTIVE, INACTIVE, FROZEN, LOST_CARD
    }

    // 构造函数
    public Reader(String readerId, String name, String gender, String phone, 
                  String email, String department, ReaderType type) {
        this.readerId = readerId;
        this.name = name;
        this.gender = gender;
        this.phone = phone;
        this.email = email;
        this.department = department;
        this.type = type;
        this.registerDate = LocalDate.now();
        this.status = ReaderStatus.ACTIVE;
        setBorrowPrivileges(type);
    }

    private void setBorrowPrivileges(ReaderType type) {
        switch (type) {
            case TEACHER:
                this.maxBorrowCount = 20;
                this.maxBorrowDays = 60;
                this.expiryDate = LocalDate.now().plusYears(3);
                break;
            case STUDENT:
                this.maxBorrowCount = 10;
                this.maxBorrowDays = 30;
                this.expiryDate = LocalDate.now().plusYears(2);
                break;
            case STAFF:
                this.maxBorrowCount = 15;
                this.maxBorrowDays = 45;
                this.expiryDate = LocalDate.now().plusYears(2);
                break;
            case EXTERNAL:
                this.maxBorrowCount = 5;
                this.maxBorrowDays = 21;
                this.expiryDate = LocalDate.now().plusYears(1);
                break;
        }
    }

    // Getter和Setter方法
    public String getReaderId() { return readerId; }
    public void setReaderId(String readerId) { this.readerId = readerId; }

    public String getName() { return name; }
    public void setName(String name) { this.name = name; }

    public String getGender() { return gender; }
    public void setGender(String gender) { this.gender = gender; }

    public String getPhone() { return phone; }
    public void setPhone(String phone) { this.phone = phone; }

    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email; }

    public String getDepartment() { return department; }
    public void setDepartment(String department) { this.department = department; }

    public ReaderType getType() { return type; }
    public void setType(ReaderType type) { 
        this.type = type; 
        setBorrowPrivileges(type);
    }

    public LocalDate getRegisterDate() { return registerDate; }
    public void setRegisterDate(LocalDate registerDate) { this.registerDate = registerDate; }

    public LocalDate getExpiryDate() { return expiryDate; }
    public void setExpiryDate(LocalDate expiryDate) { this.expiryDate = expiryDate; }

    public ReaderStatus getStatus() { return status; }
    public void setStatus(ReaderStatus status) { this.status = status; }

    public int getMaxBorrowCount() { return maxBorrowCount; }
    public int getMaxBorrowDays() { return maxBorrowDays; }

    @Override
    public String toString() {
        return String.format("%s (%s) - %s", name, readerId, department);
    }
}
